import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite';
import vueJsx from '@vitejs/plugin-vue-jsx';
import Components from 'unplugin-vue-components/vite';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import ElementPlus from 'unplugin-element-plus/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

import path from 'path'
// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'), // 设置别名 @ 指向 src 目录
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        // quietDeps: true, // 可以尝试，但在高版本中似乎不起作用
        silenceDeprecations: ['legacy-js-api'],
      },
    },
  },
  plugins: [
    // vue 3
    vue(),
    vueJsx(),
    ElementPlus({}),
    // 按需引入组件
    AutoImport({
      include: [
        /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
        /\.vue$/,
        /\.vue\?vue/, // .vue
        /\.md$/ // .md
      ],
      imports: [
        'vue',
        'vue-router',
      ],
      dts: 'src/types/auto-imports.d.ts',
      // dts: false,
      resolvers: [ElementPlusResolver()],
      eslintrc: {
        enabled: false, // Default `false`
        filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
        globalsPropValue: true // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
      }
    }),
    createSvgIconsPlugin({
      iconDirs: [path.resolve(__dirname, 'src/components/icons/svg')], // icon存放的目录，自定义
      symbolId: 'icon-[dir]-[name]', // symbol的命名
    }),
    //other plugins
  ],
})
